#pragma once

#include <gtest/gtest.h>

#include <Python.h>
#include <pybind11/embed.h>
#include <pybind11/eval.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "qlib/core/dll.h"

#include <memory>

namespace py = pybind11;
using namespace qlib;

TEST(PythonTest, BasicAssertion) {
  // 设置 Python 主目录
  const char* variableValue = std::getenv("PYTHONHOME");
  if (variableValue) {
    size_t wcharCount = mbstowcs(NULL, variableValue, 0);
    std::wstring wtext(wcharCount, L'\0');
    mbstowcs(&wtext[0], variableValue, wcharCount);
    const wchar_t* wtextPtr = wtext.c_str();
    Py_SetPythonHome(wtextPtr);
  }
  // 初始化 Python 解释器
  static py::scoped_interpreter guard{};
  // 构建 Python 代码
  std::string python_code =
      "import sys\n"
      "sys.path.append('./')\n";
  py::exec(python_code);

  auto& librarys = Get::get_librarys();
  librarys.resize(1);

  // Library::s_ptr& library = librarys[0];
  Library::s_ptr& library = librarys[0];
  library = Library::create();
  library->name = "kernel library";
  library->unit = 0.01;
  Get::set_library(library, 0);

  py::module module = py::module::import("test");
  py::function test1 = module.attr("test1");
  test1();

  std::cout << library->name << std::endl;
  std::cout << library->unit << std::endl << std::endl;

  library->name = "XXX";
  library->unit = 100;

  py::function test2 = module.attr("test2");
  test2();

  py::function test3 = module.attr("test3");
  test3();

  std::cout << library->name << std::endl;
  std::cout << library->unit << std::endl;
}

// TEST(Vec2d_Test, BasicAssertion) {
//   py::module module = py::module::import("Vec2d_test");
//   py::function test = module.attr("test");

//   auto& vec2d = Get_Test::vec2d;
//   auto& vec2dArray = Get_Test::vec2dArray;
//   vec2d = Vec2d(1.0, 1.0);
//   vec2dArray = {{1.0, 1.0}};

//   auto& doubleArray = Get_Test::doubleArray;

//   test();

//   EXPECT_EQ(vec2d == Vec2d(2.0, 2.0), true);
//   ASSERT_EQ(vec2dArray.size() == 10, true);
//   for (size_t i = 0; i < 10; i++) {
//     EXPECT_EQ(vec2dArray[i] == Vec2d(i, i * 10), true);
//   }

//   ASSERT_EQ(doubleArray.size() == 10, true);
//   for (size_t i = 0; i < 10; i++) {
//     EXPECT_EQ(doubleArray[i] == i, true);
//   }
// }

// TEST(Repetition_Test, BasicAssertion) {
//   py::module module = py::module::import("Repetition_test");
//   py::function test = module.attr("test");

//   test();
// }